package com.example.mydy.utils;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Retrofit客户端单例类
 */
public class RetrofitClient {
    private static final String BASE_URL = "https://api.example.com/v1/"; // 替换为实际的API地址
    private static Retrofit retrofit = null;

    /**
     * 获取Retrofit实例
     */
    public static Retrofit getClient() {
        if (retrofit == null) {
            OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .connectTimeout(15, TimeUnit.SECONDS)
                    .readTimeout(15, TimeUnit.SECONDS)
                    .writeTimeout(15, TimeUnit.SECONDS)
                    .build();

            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .client(okHttpClient)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }

    /**
     * 重置Retrofit实例（切换服务器地址时使用）
     */
    public static void resetClient() {
        retrofit = null;
    }
} 